﻿
Imports xmlctrl
Imports elpmis
Imports lpmsengi
Imports avacom

Public Class idcard
    Inherits cacheControlProcessor

    Public Overrides Function pathidentity() As String
        Return path.idcard
    End Function

    Private Shared Function serverUrl(ByVal context As httpContext) As String
        Return urlUtils.combineUrl(context.url().protocol, context.url().user, context.url().password,
                                   context.url().host, context.url().port, emptyString, emptyString, emptyString)
    End Function

    Protected Overrides Function processImpl(ByVal context As httpContext, ByRef control As xmlcontrol) As Boolean
        Dim id As String = Nothing
        id = context.url().query(query.id)
        Dim width As Int64 = npos
        Dim height As Int64 = npos
        If Not parseSize(context, width, height) Then
            width = 30
            height = 35
        End If
        Dim notarget As Boolean = False
        Dim target As String = Nothing
        target = context.url().query(query.targetUrl)
        If isemptystring(target) Then
            target = serverUrl(context)
            notarget = True
        Else
            notarget = False
        End If
        lpmsctx.insertThreadStaticVariable("imgurl", typeDefination.string,
                                           urlgenerator.portrait(serverUrl(context), id, height:=height, width:=width))
        lpmsctx.insertThreadStaticVariable("nick", typeDefination.string,
                                           Convert.ToString(nick.process(context, id, format.plain)))
        lpmsctx.insertThreadStaticVariable("sign", typeDefination.string,
                                           Convert.ToString(sign.process(context, id, format.plain)))
        lpmsctx.insertThreadStaticVariable("imgwidth", typeDefination.int, width)
        lpmsctx.insertThreadStaticVariable("imgheight", typeDefination.int, height)
        lpmsctx.insertThreadStaticVariable("targetUrl", typeDefination.string, target)
        lpmsctx.insertThreadStaticVariable("notarget", typeDefination.bool, notarget)
        Return context.createControl(New nameLpmsControl("idcard")).render()
    End Function
End Class
